﻿Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Linq
Imports System.Web
Imports Forecast.Logica.Enumeradores
Imports Forecast.Logica.Modelos

Namespace Servicios

    Public Class ServClientes

        Public Function ListadoClientes(IdEntityF As Integer) As List(Of Clientes)
            Dim cmd As New SqlCommand()
            Dim da As SqlDataAdapter
            Dim ds As DataSet
            Dim drReader As SqlDataReader

            Dim conection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString.ToString)
            conection.Open()

            cmd.Connection = conection
            cmd.CommandText = "FC_Clientes_Search"
            cmd.CommandType = CommandType.StoredProcedure

            cmd.Parameters.Add("@IdEntityF ", Data.SqlDbType.VarChar)
            cmd.Parameters("@IdEntityF ").Value = IdEntityF

            da = New SqlDataAdapter()
            drReader = cmd.ExecuteReader()

            Dim ListClientes = New List(Of Clientes)()

            While drReader.Read()
                Dim clientes = New Clientes()

                If (drReader("IdCustomer") IsNot System.DBNull.Value) Then
                    clientes.IdCustomer = drReader("IdCustomer").ToString()
                End If
                If (drReader("Codigo") IsNot System.DBNull.Value) Then
                    clientes.Codigo = drReader("Codigo").ToString()
                End If
                If (drReader("Name") IsNot System.DBNull.Value) Then
                    clientes.Name = drReader("Name").ToString()
                End If
                If (drReader("IdEntityF") IsNot System.DBNull.Value) Then
                    clientes.IdEntityF = drReader("IdEntityF").ToString()
                End If
               

                ListClientes.Add(clientes)
            End While

            drReader.Close()
            Return ListClientes

        End Function

        Public Function SearchCliente(IdEntityF As Integer) As DataTable
            Dim cn As New SqlConnection()
            Dim cmd As New SqlCommand()
            Dim da As SqlDataAdapter
            Dim ds As DataSet

            Dim ConnString As String = ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString.ToString
            cn.ConnectionString = ConnString
            cmd = New SqlCommand()
            cmd.Connection = cn
            cmd.CommandText = "FC_Clientes_Search"
            cmd.CommandType = CommandType.StoredProcedure

            cmd.Parameters.Add("@IdEntityF", Data.SqlDbType.VarChar)
            cmd.Parameters("@IdEntityF").Value = IdEntityF

            da = New SqlDataAdapter()
            da.SelectCommand = cmd
            ds = New DataSet()
            da.Fill(ds)
            Return ds.Tables(0)
        End Function
        'Implements IServClientes
        'Public Function ObtenerClientes(IdEntityF As Integer) As Clientes Implements IServClientes.ObtenerClientes
        '    Dim cmd As New SqlCommand()
        '    Dim da As SqlDataAdapter
        '    Dim ds As DataSet
        '    Dim drReader As SqlDataReader

        '    Dim conection As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString.ToString)
        '    conection.Open()

        '    cmd.Connection = conection
        '    cmd.CommandText = "FC_Clientes_Search"
        '    cmd.CommandType = CommandType.StoredProcedure

        '    cmd.Parameters.Add("@IdEntityF ", Data.SqlDbType.VarChar)
        '    cmd.Parameters("@IdEntityF ").Value = IdEntityF

        '    da = New SqlDataAdapter()
        '    drReader = cmd.ExecuteReader()

        '    Dim clientes = New Clientes

        '    'While drReader.Read()
        '    '    If (drReader("IdUsuario") IsNot System.DBNull.Value) Then
        '    '        usuario.IdUsuario = drReader("IdUsuario").ToString()
        '    '    End If
        '    '    If (drReader("Username") IsNot System.DBNull.Value) Then
        '    '        usuario.Username = drReader("Username").ToString()
        '    '    End If
        '    '    If (drReader("IdRole") IsNot System.DBNull.Value) Then
        '    '        usuario.idRole = drReader("IdRole").ToString()
        '    '    End If
        '    '    If (drReader("DesRole") IsNot System.DBNull.Value) Then
        '    '        usuario.idRole = drReader("DesRole").ToString()
        '    '    End If
        '    '    If (drReader("Name") IsNot System.DBNull.Value) Then
        '    '        usuario.idRole = drReader("Name").ToString()
        '    '    End If
        '    '    If (drReader("IdCountry") IsNot System.DBNull.Value) Then
        '    '        usuario.idRole = drReader("IdCountry").ToString()
        '    '    End If
        '    '    If (drReader("DesCountry") IsNot System.DBNull.Value) Then
        '    '        usuario.idRole = drReader("DesCountry").ToString()
        '    '    End If
        '    '    If (drReader("Active") IsNot System.DBNull.Value) Then
        '    '        usuario.Active = drReader("Active").ToString()
        '    '    End If

        '    'End While


        '    drReader.Close()
        '    Return clientes


        'End Function

    End Class

    Public Interface IServClientes
        Function ObtenerClientes(username As String, password As String) As Clientes


    End Interface
  
End Namespace

